﻿using System;
using DDotNet.ORM.ORMapping.Attribute;
using DDotNet.ORM.ORMapping.Attribute.DirectAccess;
using DDotNet.ORM.ORMapping.OREntity;

namespace GenericTests.Entities
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable()]
    [DBMapping("MainDB")]
    [DirectEntityMapping("tb_Shop", AllowDelete = true, AllowInsert = true, AllowUpdate = true)]
    public sealed class Shop : BusinessEntityBase
    {
        #region Construtor

        public Shop()
        {
            this._ShopItens = new ShopItemCollection();
        }

        #endregion

        private int _ID;

        /// <summary>
        /// 
        /// </summary>
        [EntityPrimaryKey(true)]
        [PropertyMapping("IDShop")]
        public int ID
        {
            get { return this._ID; }
            set
            {
                this._ID = value;
                base.MarkDirty("ID");
            }
        }


        private int _IDCustomer;

        private DateTime _ShopDate;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("ShopDate")]
        public DateTime ShopDate
        {
            get { return this._ShopDate; }
            set
            {
                this._ShopDate = value;
                base.MarkDirty("ShopDate");
            }
        }

        /// <summary>
        ///
        /// </summary>
        [EntityForeignKey("ID")]
        [PropertyMapping("IDCustomer")]
        public int IDCustomer
        {
            get { return this._IDCustomer; }
            set
            {
                this._IDCustomer = value;
                base.MarkDirty("IDCustomer");
            }
        }

        
        private ShopItemCollection _ShopItens;

        [ChildrenPropertyMapping("IDShop")]
        [ChildrenPropertySettings(CascadeDelete = true, CascadeUpdate = true, AutomaticLinkLoad = true)]
        public ShopItemCollection ShopItens
        {
            get { return this._ShopItens; }
            set
            {
                this._ShopItens = value;

                // Configura o Pai do Endereço
                if (this._ShopItens != null)
                {
                    this._ShopItens.Parent = this;
                }

                base.MarkDirty("ShopItens");
            }
        }
        
        
    }
}